import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NoteOrderService } from 'src/app/service/me/note-order.service';
import { MessageService } from 'src/app/service/message.service';

@Component({
  selector: 'app-msg',
  templateUrl: './msg.component.html',
  styleUrls: ['./msg.component.scss']
})
export class MsgComponent implements OnInit {
  cols = {
    custName: '用户姓名',
    custUId: '用户编号',
    custTel: '用户手机',
    details: '开通业务',
  }
  
  constructor(
    private noteOrder: NoteOrderService,
    private message: MessageService,
    private router: Router
  ) { }

  ngOnInit(): void {
    this.getNoteOrders()
  }

  data: any = []
  dataLoading = false
  total = 0
  pageSize = 10
  pageIndex = 1
  getNoteOrders(){
    this.dataLoading = true
    this.noteOrder.getMesList(this.pageIndex, this.pageSize).subscribe({
      next: (res: any) => {
        console.log(res)
        if(res && res.resultList && res.resultList.length > 0){
          this.data = res.resultList.map((_: any) => {
            _.details = _.details.map((_: any) => _.name)
            return _
          })
        }
        this.dataLoading = false
      },
      error: error => {
        this.message.error(error)
        this.dataLoading = false
      }
    })
  }
  
  addMsg(){
    this.router.navigate(['/me/msg/add'])
  }

}
